var http = require('http');
//var  fs = require('fs');
var url=require("url");
var querystring = require('querystring');
//var express = require('express');
//var iconv = require('iconv-lite');
//var encoding = require('encoding');
var postData = querystring.stringify({
    "cid": "53cc25f2ce18e71034e60383",
    "related_contest_count": "9",
    "include_related_creator": "false",
    "request_sizing_chart_info": "true",
    "_buckets":"",
    "_experiments":""

})
// var options = {
//     hostname: 'www.wish.com',
//     path: '/api/product/get',
//     method: 'POST',
//     headers: {
//         'Accept': 'application/json, text/javascript, *!/!*; q=0.01',
//         'Accept-Encoding': '*',
//         'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',
//         'Connection': 'keep-alive',
//         'Content-Length': '137',
//         'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
//         'Cookie': 'sweeper_session="ZDA0NmUyNGEtNDBlMi00YjdkLWIxODgtYTFmOWMyZTcxY2QzMjAxNi0wMy0xMCAxNjowNjo1MC4zODE0NjI=|1457626010|74dc30c550b66a2b78c9b6e6dc4966a7a8d327b2"; _xsrf=b5793de5113242f2a4863c734839d788; __utmt=1; __utma=96128154.1274647403.1457626088.1457955853.1457959635.15; __utmb=96128154.15.10.1457959635; __utmc=96128154; __utmz=96128154.1457855828.9.2.utmcsr=wish.com|utmccn=(referral)|utmcmd=referral|utmcct=/c/567b95afab3afa26adb6c2c1; bsid=ace6f547893149178d8a2485c10972b9; sweeper_uuid=4ab4cf7176894389982dd27b93d8f516',
//         'Host': 'www.wish.com',
//         'Origin': 'https://www.wish.com',
//         'Referer': 'https://www.wish.com/',
//         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
//         'X-Requested-With':"XMLHttpRequest",
//         'X-XSRFToken': 'b5793de5113242f2a4863c734839d788'
//     }
// }
http.createServer(function (req, res) {
    var callbackName=url.parse(req.url,true).query.callback;
    var page=url.parse(req.url,true).query.page;
    var req2 = http.get("http://50tu.com/ajax.php?p="+page+"&id=54", function (res2) {
        var size = 0;
        var chunks = [];
        res2.on('data', function(chunk){
            size += chunk.length;
            chunks.push(chunk);
        });
        res2.on('end', function(){
            var data = Buffer.concat(chunks, size);
            console.log(data.toString())
            res.end(callbackName+'('+data.toString()+')');
        });
    });
    req2.on("error", function (e) {
        console.log('Error:' + e.message)
    })
    req2.write(querystring.stringify(url.parse(req.url,true).query));
    //req2.write(postData);
    req2.end();

}).listen(1337, "127.0.0.1");
console.log('Server1 running at flickr/');





